<!DOCTYPE html>

<html lang="en" data-content_root="../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <title>LINK_LIBRARIES_STRATEGY &mdash; CMake 4.1.1 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=a2c47e09" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css?v=4d06bd55" />
    
    <script src="../_static/documentation_options.js?v=e6a937a4"></script>
    <script src="../_static/doctools.js?v=9bcbadda"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    
    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="LINK_LIBRARY_OVERRIDE" href="LINK_LIBRARY_OVERRIDE.html" />
    <link rel="prev" title="LINK_LIBRARIES_ONLY_TARGETS" href="LINK_LIBRARIES_ONLY_TARGETS.html" />
 

  </head><body>
    <input id="sidebar-check" type="checkbox" />
    <label id="sidebar-overlay" for="sidebar-check"></label>



    <div class="related relbar1" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="LINK_LIBRARY_OVERRIDE.html" title="LINK_LIBRARY_OVERRIDE"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="LINK_LIBRARIES_ONLY_TARGETS.html" title="LINK_LIBRARIES_ONLY_TARGETS"
             accesskey="P">previous</a> |</li>
  <li>
    <label class="sidebar-toggle" for="sidebar-check"></label>
  </li>
  <li class="rootlink">
    <img src="../_static/cmake-logo-16.png" width="16" height="16" alt=""/>
    <a href="https://cmake.org/">CMake 4.1.1</a>
    <span class="reldelim1"> &#187;</span>
  </li>
  <li>
    <a href="../index.html">Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" accesskey="U">cmake-properties(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">LINK_LIBRARIES_STRATEGY</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="link-libraries-strategy">
<span id="prop_tgt:LINK_LIBRARIES_STRATEGY"></span><h1>LINK_LIBRARIES_STRATEGY<a class="headerlink" href="#link-libraries-strategy" title="Link to this heading">¶</a></h1>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.31.</span></p>
</div>
<p>Specify a strategy for ordering a target's direct link dependencies
on linker command lines.  This property is initialized by the value of the
<span class="target" id="index-0-variable:CMAKE_LINK_LIBRARIES_STRATEGY"></span><a class="reference internal" href="../variable/CMAKE_LINK_LIBRARIES_STRATEGY.html#variable:CMAKE_LINK_LIBRARIES_STRATEGY" title="CMAKE_LINK_LIBRARIES_STRATEGY"><code class="xref cmake cmake-variable docutils literal notranslate"><span class="pre">CMAKE_LINK_LIBRARIES_STRATEGY</span></code></a> variable if it is set when a
target is created.</p>
<p>CMake generates a target's link line using its <a class="reference internal" href="../manual/cmake-buildsystem.7.html#target-link-properties"><span class="std std-ref">Target Link Properties</span></a>.
In particular, the <span class="target" id="index-0-prop_tgt:LINK_LIBRARIES"></span><a class="reference internal" href="LINK_LIBRARIES.html#prop_tgt:LINK_LIBRARIES" title="LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">LINK_LIBRARIES</span></code></a> target property records the
target's direct link dependencies, typically populated by calls to
<span class="target" id="index-0-command:target_link_libraries"></span><a class="reference internal" href="../command/target_link_libraries.html#command:target_link_libraries" title="target_link_libraries"><code class="xref cmake cmake-command docutils literal notranslate"><span class="pre">target_link_libraries()</span></code></a>.  Indirect link dependencies are
propagated from those entries of <span class="target" id="index-1-prop_tgt:LINK_LIBRARIES"></span><a class="reference internal" href="LINK_LIBRARIES.html#prop_tgt:LINK_LIBRARIES" title="LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">LINK_LIBRARIES</span></code></a> that name
library targets by following the transitive closure of their
<span class="target" id="index-0-prop_tgt:INTERFACE_LINK_LIBRARIES"></span><a class="reference internal" href="INTERFACE_LINK_LIBRARIES.html#prop_tgt:INTERFACE_LINK_LIBRARIES" title="INTERFACE_LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">INTERFACE_LINK_LIBRARIES</span></code></a> properties.  CMake supports multiple
strategies for nominally ordering direct and indirect link dependencies,
which are then filtered for <a class="reference internal" href="#toolchain-specific-behavior">Toolchain-Specific Behavior</a>.</p>
<p>Consider this example for the strategies below:</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">add_library(</span><span class="no">A</span><span class="w"> </span><span class="no">STATIC</span><span class="w"> </span><span class="p">...</span><span class="nf">)</span>
<span class="nf">add_library(</span><span class="no">B</span><span class="w"> </span><span class="no">STATIC</span><span class="w"> </span><span class="p">...</span><span class="nf">)</span>
<span class="nf">add_library(</span><span class="no">C</span><span class="w"> </span><span class="no">STATIC</span><span class="w"> </span><span class="p">...</span><span class="nf">)</span>
<span class="nf">add_executable(</span><span class="nb">main</span><span class="w"> </span><span class="p">...</span><span class="nf">)</span>
<span class="nf">target_link_libraries(</span><span class="no">B</span><span class="w"> </span><span class="no">PRIVATE</span><span class="w"> </span><span class="no">A</span><span class="nf">)</span>
<span class="nf">target_link_libraries(</span><span class="no">C</span><span class="w"> </span><span class="no">PRIVATE</span><span class="w"> </span><span class="no">A</span><span class="nf">)</span>
<span class="nf">target_link_libraries(</span><span class="nb">main</span><span class="w"> </span><span class="no">PRIVATE</span><span class="w"> </span><span class="no">A</span><span class="w"> </span><span class="no">B</span><span class="w"> </span><span class="no">C</span><span class="nf">)</span>
</pre></div>
</div>
<p>The supported strategies are:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">REORDER_MINIMALLY</span></code></dt><dd><p>Entries of <span class="target" id="index-2-prop_tgt:LINK_LIBRARIES"></span><a class="reference internal" href="LINK_LIBRARIES.html#prop_tgt:LINK_LIBRARIES" title="LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">LINK_LIBRARIES</span></code></a> always appear first and in their
original order.  Indirect link dependencies not satisfied by the
original entries may be reordered and de-duplicated with respect to
one another, but are always appended after the original entries.
This may result in less efficient link lines, but gives projects
control of ordering among independent entries.  Such control may be
important when intermixing link flags with libraries, or when multiple
libraries provide a given symbol.</p>
<p>This is the default.</p>
<p>In the above example, this strategy computes a link line for <code class="docutils literal notranslate"><span class="pre">main</span></code>
by starting with its original entries <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">B</span> <span class="pre">C</span></code>, and then appends
another <code class="docutils literal notranslate"><span class="pre">A</span></code> to satisfy the dependencies of <code class="docutils literal notranslate"><span class="pre">B</span></code> and <code class="docutils literal notranslate"><span class="pre">C</span></code> on <code class="docutils literal notranslate"><span class="pre">A</span></code>.
The nominal order produced by this strategy is <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">B</span> <span class="pre">C</span> <span class="pre">A</span></code>.</p>
<p>Note that additional filtering for <a class="reference internal" href="#toolchain-specific-behavior">Toolchain-Specific Behavior</a>
may de-duplicate <code class="docutils literal notranslate"><span class="pre">A</span></code> on the actual linker invocation in the
generated build system, resulting in either <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">B</span> <span class="pre">C</span></code> or <code class="docutils literal notranslate"><span class="pre">B</span> <span class="pre">C</span> <span class="pre">A</span></code>.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">REORDER_FREELY</span></code></dt><dd><p>Entries of <span class="target" id="index-3-prop_tgt:LINK_LIBRARIES"></span><a class="reference internal" href="LINK_LIBRARIES.html#prop_tgt:LINK_LIBRARIES" title="LINK_LIBRARIES"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">LINK_LIBRARIES</span></code></a> may be reordered, de-duplicated,
and intermixed with indirect link dependencies.  This may result in
more efficient link lines, but does not give projects any control of
ordering among independent entries.</p>
<p>In the above example, this strategy computes a link line for <code class="docutils literal notranslate"><span class="pre">main</span></code>
by re-ordering its original entries <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">B</span> <span class="pre">C</span></code> to satisfy the
dependencies of <code class="docutils literal notranslate"><span class="pre">B</span></code> and <code class="docutils literal notranslate"><span class="pre">C</span></code> on <code class="docutils literal notranslate"><span class="pre">A</span></code>.
The nominal order produced by this strategy is <code class="docutils literal notranslate"><span class="pre">B</span> <span class="pre">C</span> <span class="pre">A</span></code>.</p>
</dd>
</dl>
<section id="toolchain-specific-behavior">
<h2>Toolchain-Specific Behavior<a class="headerlink" href="#toolchain-specific-behavior" title="Link to this heading">¶</a></h2>
<p>After one of the above strategies produces a nominal order among
direct and indirect link dependencies, the actual linker invocation
in the generated build system may de-duplicate entries based on
platform-specific requirements and linker capabilities.
See policy <span class="target" id="index-0-policy:CMP0156"></span><a class="reference internal" href="../policy/CMP0156.html#policy:CMP0156" title="CMP0156"><code class="xref cmake cmake-policy docutils literal notranslate"><span class="pre">CMP0156</span></code></a>.</p>
<p>For example, if the <code class="docutils literal notranslate"><span class="pre">REORDER_MINIMALLY</span></code> strategy produces <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">B</span> <span class="pre">C</span> <span class="pre">A</span></code>,
the actual link line may de-duplicate <code class="docutils literal notranslate"><span class="pre">A</span></code> as follows:</p>
<ul class="simple">
<li><p>If <code class="docutils literal notranslate"><span class="pre">A</span></code> is a static library and the linker re-scans automatically,
the first occurrence is kept, resulting in <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">B</span> <span class="pre">C</span></code>.
See policy <span class="target" id="index-0-policy:CMP0179"></span><a class="reference internal" href="../policy/CMP0179.html#policy:CMP0179" title="CMP0179"><code class="xref cmake cmake-policy docutils literal notranslate"><span class="pre">CMP0179</span></code></a></p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">A</span></code> is a shared library on Windows, the first
occurrence is kept, resulting in <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">B</span> <span class="pre">C</span></code>.</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">A</span></code> is a shared library on macOS or UNIX platforms, the last
occurrence is kept, resulting in <code class="docutils literal notranslate"><span class="pre">B</span> <span class="pre">C</span> <span class="pre">A</span></code>.</p></li>
</ul>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
  <div>
    <h3>Table of Contents</h3>
    <ul>
<li><a class="reference internal" href="#">LINK_LIBRARIES_STRATEGY</a><ul>
<li><a class="reference internal" href="#toolchain-specific-behavior">Toolchain-Specific Behavior</a></li>
</ul>
</li>
</ul>

  </div>
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="LINK_LIBRARIES_ONLY_TARGETS.html"
                          title="previous chapter">LINK_LIBRARIES_ONLY_TARGETS</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="LINK_LIBRARY_OVERRIDE.html"
                          title="next chapter">LINK_LIBRARY_OVERRIDE</a></p>
  </div>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/prop_tgt/LINK_LIBRARIES_STRATEGY.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="LINK_LIBRARY_OVERRIDE.html" title="LINK_LIBRARY_OVERRIDE"
             >next</a> |</li>
        <li class="right" >
          <a href="LINK_LIBRARIES_ONLY_TARGETS.html" title="LINK_LIBRARIES_ONLY_TARGETS"
             >previous</a> |</li>
  <li>
    <label class="sidebar-toggle" for="sidebar-check"></label>
  </li>
  <li class="rootlink">
    <img src="../_static/cmake-logo-16.png" width="16" height="16" alt=""/>
    <a href="https://cmake.org/">CMake 4.1.1</a>
    <span class="reldelim1"> &#187;</span>
  </li>
  <li>
    <a href="../index.html">Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" >cmake-properties(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">LINK_LIBRARIES_STRATEGY</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
    &#169; Copyright 2000-2025 Kitware, Inc. and Contributors.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
    </div>
<script type="text/javascript">
(function() {
  "use strict";
  const hide = () => document.getElementById("sidebar-check").checked = false;
  addEventListener("keydown", e => (e.key === "Escape") && hide());
  addEventListener("click", e => (e.target.tagName === "A") && hide());
  addEventListener("hashchange", hide)
})();
</script>
  </body>
</html>